package com.tensai.study.java.newconcept.concurrentprogramming;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.concurrent.atomic.DoubleAdder;
import java.util.stream.IntStream;

/**
 * @author Tensai
 */
@Slf4j
public class DoubleAdderTest {


	/**
	 * 并发加和
	 */
	@Test
	public void test() {
		DoubleAdder doubleAdder = new DoubleAdder();
		IntStream.range(0, 10).forEach(it -> {
			doubleAdder.add(it * 1.0);
			log.info("sum -> {}, value -> {}", doubleAdder.sum(), doubleAdder.doubleValue());
		});
	}
}
